﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Controls;

namespace ControlExplorer.View
{
    /// <summary>
    /// Proxy class used to force the reevaluation of Binding when the Theme was changed.
    /// Some Bindings where being updated automatically, but some other weren't.
    /// Bypassing all the StaticResources invocations by this proxy, we can force the reevaluation.
    /// </summary>
    public class AppResourcesProxy
        : FrameworkElement, INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;

        public AppResourcesProxy() 
        {
            ViewModel.Instance.PropertyChanged += Instance_PropertyChanged;
        }

        void Instance_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "InheritPhoneTheme" && PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(""));
            }
        }

        public object this[string styleName]
        {
            get
            {
                return Application.Current.Resources[styleName];
            }
        }        
    }
}
